package logic

import (
	"context"
	"fmt"
	"rpc/model/redis"

	"rpc/internal/svc"
	"rpc/pb/cart"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelLogic {
	return &CartDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartDelLogic) CartDel(in *cart.CartDelRequest) (*cart.CartDelResponse, error) {
	// todo: add your logic here and delete this line

	err := redis.CartDel(in.UserId, in.GoodsId)
	if err != nil {
		logx.Error("删除失败")
		return nil, fmt.Errorf("删除失败")
	}

	return &cart.CartDelResponse{Success: true}, nil
}
